﻿/**************************************************************************** 
 * Copyright (c) 2011 ECAlford
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 *****************************************************************************/

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections;



namespace AceBots.Windows.Utilities
{
    public class ShortValueItem
    {
        public ShortValueItem(string pstrName, short psVaL)
        {
            Name = pstrName;
            Value = psVaL;
        }
        public short Value { get; set; }
        public string Name { get; set; }
    }
    public class ConfigData
    {
        private XmlDocument myXmlDoc;
        public ConfigData(string psFilePath)
        {
            myXmlDoc = new XmlDocument();
            myXmlDoc.Load(psFilePath);
        }
        public void AddItemListToComboBox(ComboBox pobjCombo,string pstrShortValueListName)
        {
            string sXpath = @"//ShortValueList[@Name=""" + pstrShortValueListName + @"""]/Item";
            Utilities.ShortValueItem objVItem;
            XmlNode objNode;
            string sVal;
            string sName;
            
            ArrayList myList = new ArrayList();
            XmlNodeList objNodeList = myXmlDoc.SelectNodes(sXpath);
            for (int i = 0; i < objNodeList.Count; i++)
            {
                objNode = objNodeList.Item(i);
                sName = objNode.Attributes.Item(1).InnerText;
                sVal = objNode.Attributes.Item(2).InnerText;
                objVItem = new ShortValueItem(sName,Convert.ToInt16(sVal));
                myList.Add(objVItem);
            }
            pobjCombo.DataSource=myList;
            pobjCombo.DisplayMember = "Name";
            pobjCombo.ValueMember = "Value";
            

        }
    }

}
